# -*- coding: UTF-8 -*-  
import pygame

from settings import Settings
from ship import Ship
from pygame.sprite import Group

import game_functions as gf

def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()

    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))

    pygame.display.set_caption("Alien")

    #创建飞船
    ship = Ship(ai_settings, screen)

    # 创建存储子弹的编组
    bullets = Group()

    # 创建一个外星人
    aliens = Group()

    # 创建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏主循环
    while True :

        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)

        # 更新飞船移动状态
        ship.update()

        # 更新子弹位置并删除已消失子弹
        gf.update_bullets(bullets)

        # 每次循环时都重新绘制屏幕
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)

        
run_game()                